package com.wangtao.firstapp.adapters;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.ArticleGuide;

/**
 * 第二个页面文章下 原创文章全方位指南  的适配器
 * Created by lanouhn on 16/8/25.
 */
public class ArticleGuideAdapter extends BaseAdapter {
    private Context context;
    private ArticleGuide articleGuide;

    public ArticleGuideAdapter(Context context, ArticleGuide articleGuide) {
        this.context = context;
        this.articleGuide = articleGuide;
    }

    @Override
    public int getCount() {
        return articleGuide.getData().getInsert_element().size();
    }

    @Override
    public Object getItem(int position) {
        return articleGuide.getData().getInsert_element().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.articleguide, null);
            holder = new ViewHolder();
            holder.iv_articleguide = (ImageView) convertView.findViewById(R.id.iv_articleguide);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(articleGuide.getData().getInsert_element().get(position).getPhoto()).config(Bitmap.Config.RGB_565).into(holder.iv_articleguide);
        return convertView;
    }

    public class ViewHolder {
        private ImageView iv_articleguide;
    }
}
